package com.beimin.evedata.hibernate;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

import com.beimin.evedata.model.ram.RamActivity;
import com.beimin.evedata.model.ram.TypeActivityMaterial;
import com.beimin.evedata.repository.RamRepository;

public class HibRamRepository implements RamRepository{
	private final SessionFactory sf;

	public HibRamRepository(SessionFactory sf) {
		this.sf = sf;
	}
	@SuppressWarnings("unchecked")
	public Collection<RamActivity> getActivities() {
		return sf.getCurrentSession().createCriteria(RamActivity.class).list();
	}

	public RamActivity getActivity(int activityID) {
		return (RamActivity) sf.getCurrentSession().get(RamActivity.class, activityID);
	}

	@SuppressWarnings("unchecked")
	public Collection<TypeActivityMaterial> getTypeActivityMaterials(int typeID, int activityID) {
		Session session = sf.getCurrentSession();
		Criteria criteria = session.createCriteria(TypeActivityMaterial.class);
		criteria.add(Restrictions.eq("id.typeID", typeID));
		criteria.add(Restrictions.eq("id.activityID", activityID));
		return criteria.list();
	}
}